package com.cold.demo.rabbitmq.demo2.$4.direct;

import com.cold.demo.rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class Publisher {
    public static String exchange = "direct_logs";

    public static void main(String[] argv) throws Exception {
        Connection connection = ConnectionUtils.getConnection();
        Channel    channel    = connection.createChannel();
        channel.exchangeDeclare(exchange, "direct");

        for (int i = 0; i < 30; i++) {
            Thread.sleep(100);
            String severity = getSeverity(argv);
            channel.basicPublish(exchange, severity, null, (System.currentTimeMillis() + "这里是消息数据" + i).getBytes());
        }
        channel.close();
        connection.close();

    }

    private static String getSeverity(String[] argv) {
        String[] routing = {"debug", "info", "error"};
        return routing[(int) (System.currentTimeMillis()%3)];
    }
}
